import {
    computed,
    reactive
} from 'vue'
import {
    defineStore
} from 'pinia'

export const userStore = defineStore('userinfo', () => {
    const userInfo = reactive({})
    const userName = computed(() => userInfo.username)
    const nickName = computed(() => userInfo.nickname)

    const setUserInfo = (info) => {
        Object.assign(userInfo, info)
    }

    const clearUserInfo = () => {
        for (const k in userInfo) {
            delete userInfo[k];
        }
    }

    return {
        userInfo,
        userName,
        nickName,
        setUserInfo,
        clearUserInfo
    }
})